home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 5 / QRZ Ham Radio Callsign Database - Volume 5.iso / files / tcpip / amiga / asrc29p.lha / ppp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-29  |  12.1 KB  |  304 lines

  1. /*
  2.  *    PPP.H
  3.  *
  4.  *    12-89    -- Katie Stevens (dkstevens@ucdavis.edu)
  5.  *           UC Davis, Computing Services
  6.  *    PPP.07    04-90    [ks] start with same peer addr during IPCP
  7.  *    PPP.08    05-90    [ks] improve statistic and trace reporting
  8.  *    PPP.09    05-90    [ks] add UPAP processing
  9.  *    PPP.10    06-90    [ks] improve keybd input of UPAP password
  10.  *                 make ppp open/close/reset work properly
  11.  *                 add peerID-to-IPaddr lookup table
  12.  *                 add peer IP lookup pool
  13.  *    PPP.13    08-90    [ks] add timestamp for PPP open
  14.  *    PPP.14    08-90    [ks] change UPAP to PAP for consistency with RFC1172
  15.  *                 add RLSD link up/down signal handling
  16.  *                 add autobaud link speed message handling
  17.  *                 make LCP/IPCP timeouts configurable
  18.  *    PPP.15    09-90    [ks] update to KA9Q NOS v900828
  19.  */
  20.  
  21. #ifndef    PPP_ALLOC
  22. #include "global.h"
  23. #include "timer.h"
  24.  
  25. /* PPP definitions */
  26. #define    PPP_ALLOC    100    /* Receiver allocation increment */
  27.  
  28. /* Bit masks for escaped element of Slip[] control block */
  29. #define PPP_BIT_BUCKET    0x01        /* Discard bytes until next frame */
  30. #define PPP_ESCAPED    0x02        /* Un-complement next rcv char */
  31. #define PPP_RCV_ACCOMP    0x04        /* Compress HDLC addr/ctl fields */
  32. #define PPP_RCV_PRCOMP    0x08        /* Compress PPP protocol field */
  33. #define PPP_XMT_ACCOMP    0x10        /* Compress HDLC addr/ctl fields */
  34. #define PPP_XMT_PRCOMP    0x20        /* Compress PPP protocol field */
  35. #define PPP_RCV_VJCOMPR    0x40        /* Van Jacobson TCP header compress */
  36. #define PPP_XMT_VJCOMPR    0x80        /* VJ TCP header compression on send */
  37.  
  38. /* Table for LCP configuration requests */
  39. struct lcpparm {
  40.     unsigned char neg_mru;        /* Attempt/accept MRU negotiation */
  41.     int16 mru;                /* Maximum Receive Unit value */
  42.     unsigned char neg_ctl_map;        /* Attempt/accept ctl map neg */
  43.     int32 ctl_map;            /* Async Control Map value */
  44.     unsigned char neg_auth_type;    /* Attempt/accept auth type neg */
  45.     int16 auth_type;            /* Authentication Type */
  46.     unsigned char neg_encr_type;    /* Attempt/accept encrpytion neg */
  47.     int16 encr_type;            /* Encryption Type */
  48.     unsigned char neg_magic_num;    /* Attempt/accept magic number neg */
  49.     int32 magic_num;            /* Magic number value */
  50.     unsigned char neg_keepalive;    /* Attempt/accept keepalive neg */
  51.     unsigned char keepalive;        /* Keepalive value */
  52.     unsigned char neg_prot_compress;    /* Attempt/accept protocol compr neg */
  53.     int prot_compress;            /* Protocol Compression boolean */
  54.     unsigned char neg_ac_compress;    /* Attmept/accept addr/ctl compr neg */
  55.     int ac_compress;            /* Addr/Ctl Compression boolean */
  56. };
  57. /* Default configuration option values */
  58. #define DEF_MRU        1500        /* Max Receive Unit = 1500 bytes */
  59. #define DEF_CTL_MAP    0xffffffff    /* Async Ctl Map = esc all controls */
  60. #define DEF_AUTH_TYPE    0x0000        /* No Authentication protocol */
  61. #define DEF_ENCR_TYPE    0x0000        /* No Encryption protocol */
  62. #define DEF_MAGIC_NUM    0x00000000    /* No Magic Number */
  63. #define DEF_LINK_QUAL    0x00        /* No Link Quality Monitoring */
  64. #define DEF_PROT_COMPR    0x00        /* No Protocol Compression */
  65. #define DEF_AC_COMPR    0x00        /* No Addr/Ctl Compression */
  66. /* Other configuration option values */
  67. #define MIN_MRU        128        /* Set a lower limit */
  68. #define PAP_AUTH_TYPE    0xc023        /* Password Auth Protocol */
  69.  
  70.  
  71. /* LCP control block */
  72. struct lcpctl {
  73.     char active;            /* 0=passive open; non-0=active open */
  74.     char lcp_state;            /* State of Link Control exchange */
  75. #define LCP_CLOSED    0x00
  76. #define LCP_LISTEN    0x01
  77. #define LCP_REQ_SENT    0x02
  78. #define LCP_ACK_RCVD    0x03
  79. #define LCP_ACK_SENT    0x04
  80. #define LCP_OPEN    0x05
  81. #define LCP_TERMINATE    0x06
  82.     unsigned char lastid;        /* ID of last REQ we sent */
  83.     struct timer lcp_tm;        /* Timer against response to our REQ */
  84.     unsigned char ack_retry;        /* Retry counter for timeouts */
  85.  
  86.     struct lcpparm initparm;        /* First request of local parameters */
  87.     struct lcpparm lclparm;        /* Negotiated local parameters */
  88.     struct lcpparm remparm;        /* Negotiated remote parameters */
  89.  
  90.     char pap_state;            /* Current state of PAP */
  91. #define PAP_CLOSED    0x00
  92. #define PAP_LISTEN    0x01
  93. #define PAP_REQ_SENT    0x02
  94. #define PAP_REQ_RCVD    0x03
  95. #define PAP_OPEN    0x04
  96.     char *pap_user;            /* Peer ID for PAP AUTH_REQ */
  97.     char *pap_pass;            /* Password for PAP AUTH_REQ */
  98. };
  99. #define LCP_TIMEOUT    10        /* 10 sec timeout wait for response */
  100. #define LCP_RETRY_MAX    10        /* Retry on timeout at most 10 times */
  101. #define LCP_TERM_RETRY     2        /* Minimal retry on TERM REQ */
  102. #define PAP_RETRY_MAX    20        /* Retry on timeout at most 20 times */
  103. #define PAP_FAIL_MAX     4        /* At most 5 attempts at peer auth */
  104. /* Permissions bit for use with userlogin() in FTPSERV.C */
  105. /* Other bit values in FTPSERV.H, AX_MBX.H               */
  106. #define PPP_ACCESS_PRIV    0x0100        /* Priv bit for PPP connection */
  107. #define PPP_PWD_LOOKUP    0x0200        /* Priv bit for peerID/pass lookup */
  108.  
  109. /* IPCP pool of addresses when remote peer requests address assignment */
  110. struct ipcppool {
  111.     int32 peer_min;            /* First IP address in pool */
  112.     int32 peer_max;            /* Last IP address in pool */
  113.     int32 peer_next;        /* Next address to assign */
  114. };
  115. #define NULLPOOL (struct ipcppool *)0
  116.  
  117. /* IPCP control block */
  118. struct ipcpctl {
  119.     char active;            /* 0=passive open; non-0=active open */
  120.     char ipcp_state;            /* State of Link Control exchange */
  121. #define IPCP_CLOSED    0x00
  122. #define IPCP_LISTEN    0x01
  123. #define IPCP_REQ_SENT    0x02
  124. #define IPCP_ACK_RCVD    0x03
  125. #define IPCP_ACK_SENT    0x04
  126. #define IPCP_OPEN    0x05
  127. #define IPCP_TERMINATE    0x06
  128.     unsigned char lastid;        /* ID of last REQ we sent */
  129.     struct timer ipcp_tm;        /* Timer against response to our REQ */
  130.     unsigned char ack_retry;        /* Retry counter for timeouts */
  131.  
  132.     int32 peer_addr;            /* IP address of remote peer */
  133.     struct ipcppool *peer_pool;        /* Pool of IP addresses for peer */
  134.     unsigned char attempt_addrs;    /* 1=send a ConfigReq with our addrs */
  135.     int32 attempt_src;            /* Addr to send with config request */
  136.     int32 attempt_dest;            /* Addr to send with config request */
  137.     unsigned char accept_addrs;        /* 1=accept addrs from remote host */
  138.     int32 accept_src;            /* Src addr given by remote host */
  139.     int32 accept_dest;            /* Dest addr given by remote host */
  140.     unsigned char neg_ip_compr;        /* 1=negotiate IP packet compression */
  141.     int16 ip_compr_type;        /* Type of IP packet compression */
  142.     unsigned char attempt_ip_compr;    /* 1=we will request IP compression */
  143.     int16 lcl_ip_compr;            /* Type of IP compression we want */
  144.     unsigned char accept_ip_compr;    /* 1=we will accept IP compr request */
  145.     int16 rem_ip_compr;            /* Type of IP compression requested */
  146. };
  147. #define IPCP_TIMEOUT     10        /* 10 sec timeout wait for response */
  148. #define IPCP_RETRY_MAX    254        /* Retry for a long time */
  149. #define IPCP_TERM_RETRY      2        /* Minimal retry on TERM REQ */
  150. #define IPCP_NVJCOMP    0x002d         /* Van Jacobson TCP header NEW */
  151. #define IPCP_OVJCOMP    0x0037        /* Van Jacobson TCP header OLD */
  152. #define DEF_IP_COMPR    0x00        /* No IP compression */
  153.  
  154. /* PPP control block */
  155. struct pppctl {
  156.     int16 calc_fcs;            /* Cummulative FCS value (rcv pkts) */
  157.     int32 ctlmap;            /* Async control map (xmt pkts) */
  158.  
  159.     char state;                /* Overall PPP link state */
  160. #define PPP_PL_DOWN    0x00            /* Physical Layer Down */
  161. #define PPP_AUTOBAUD    0x01            /* Waiting for autobaud msg */
  162. #define PPP_CLOSED    0x02            /* Idle State */
  163. #define PPP_LCP        0x03            /* Negotiating LCP options */
  164. #define PPP_PAP        0x04            /* Password authentication */
  165. #define PPP_IPCP    0x05            /* Negotiating IP options */
  166. #define PPP_OPEN    0x06            /* Link open for all traffic */
  167.     struct lcpctl lcpio;        /* Control block for LCP negotiation */
  168.     struct ipcpctl ipcpio;        /* Ctl block for IPCP negotiation */
  169.  
  170. #ifndef PPP_NO_STATS
  171.     int32 upsince;            /* Timestamp when state is PPP_OPEN */
  172.     int32 sndpkt;            /* # packets sent on PPP interface */
  173.     int16 snderr;            /* # pkts with PPP error on send */
  174.     int32 rcvpkt;            /* # packets rcvd on PPP interface */
  175.     int16 rcverr;            /* # pkts with error */
  176.     int16 csumerr;            /* # rcv pkts with bad PPP checksum */
  177.  
  178.     int16 sndlcp;            /* # LCP packets sent */
  179.     int16 sndpap;            /* # PAP packets sent */
  180.     int16 sndipcp;            /* # IPCP packets sent */
  181.     int32 sndip;            /* # IP packets sent */
  182.     int16 rcvlcp;            /* # LCP packets received */
  183.     int16 rcvpap;            /* # PAP packets received */
  184.     int16 rcvipcp;            /* # IPCP packets received */
  185.     int32 rcvip;            /* # IP packets received */
  186.     int16 rcvunk;            /* # unknown packets received */
  187. #endif
  188. };
  189. #define NULLPPPCTL    (struct pppctl *)0
  190.  
  191. struct ppphdr {
  192.     unsigned char addr;        /* Address field (always 0xff) */
  193.     char control;        /* Control field (always 0x03) */
  194.     int16 type;            /* Protocol field (IP, IPCP, LCP, PAP) */
  195. #define PPP_IP_TYPE    0x0021    /* DOD Internet Protocol */
  196. #define PPP_COMPR_TYPE    0x002d    /* Van Jacobson Compressed TCP/IP */
  197. #define PPP_UNCOMP_TYPE    0x002f    /* Van Jacobson Uncompressed TCP/IP */
  198.  
  199. #define PPP_IPCP_TYPE    0x8021    /* DOD Internet Protocol Control Protocol */
  200.  
  201. #define PPP_LCP_TYPE    0xc021    /* Link Control Protocol */
  202. #define PPP_PAP_TYPE    0xc023    /* Password Authentication Protocol */
  203. };
  204. #define PPP_HDRLEN    4    /* Max bytes for PPP/HDLC envelope header */
  205.  
  206. /* HDLC envelope constants */
  207. #define HDLC_ENVLEN    0x06    /* Max bytes for HDLC envelope (outgoing) */
  208.  
  209. #define HDLC_FLAG    0x7e    /* HDLC async start/stop flag */
  210. #define HDLC_ALL_ADDR    0x00ff    /* HDLC all-station address flag */
  211. #define HDLC_UI        0x03    /* HDLC Unnumbered Info control flag */
  212. #define HDLC_ESC_ASYNC    0x7d    /* HDLC transparency escape flag for async */
  213. #define HDLC_ESC_COMPL    0x20    /* HDLC transparency bit complement mask */
  214.  
  215. #define HDLC_FCS_START    0xffff    /* Starting bit string for FCS calculation */
  216. #define HDLC_FCS_FINAL    0xf0b8    /* FCS when summed over frame and sender FCS */
  217.  
  218. /* LCP/IPCP config packet header */
  219. struct cnfhdr {
  220.     char code;
  221. /* LCP/IPCP config packet codes */
  222. #define CONFIG_REQ    0x01
  223. #define CONFIG_ACK    0x02
  224. #define CONFIG_NAK    0x03
  225. #define CONFIG_REJ    0x04
  226. #define TERMINATE_REQ    0x05
  227. #define TERMINATE_ACK    0x06
  228. #define CODE_REJ    0x07
  229. #define PROT_REJ    0x08
  230. #define ECHO_REQ    0x09
  231. #define ECHO_REPLY    0x0a
  232. #define DISCARD_REQ    0x0b
  233. /* PAP config packet codes */
  234. #define AUTH_REQ    0x01
  235. #define AUTH_ACK    0x02
  236. #define AUTH_NAK    0x03
  237.     unsigned char id;
  238.     int16 len;
  239. };
  240. #define CNF_HDRLEN    4    /* Length of LCP/IPCP config packet header */
  241.  
  242. /* LCP/IPCP config option header */
  243. struct opthdr {
  244.     char type;
  245. /* LCP option types */
  246. #define MAX_RCV_UNIT    0x01
  247. #define ASYNC_CTL_MAP    0x02
  248. #define AUTH_TYPE    0x03
  249. #define ENCR_TYPE    0x04
  250. #define MAGIC_NUMBER    0x05
  251. #define LINK_QUALITY    0x06
  252. #define PROT_COMPRESS    0x07
  253. #define AC_COMPRESS    0x08
  254. /* IPCP option types */
  255. #define IP_ADDRS    0x01
  256. #define IP_COMPR_TYPE    0x02
  257.     unsigned char len;
  258. };
  259. #define OPT_HDRLEN    2    /* Length of LCP/IPCP config option header */
  260. #define NULLOPTHDR    (struct opthdr *)0
  261.  
  262. /* In ppp.c: */
  263. int ntohppp __ARGS((struct ppphdr *ppp, struct mbuf **bpp));
  264. int ppp_send __ARGS((struct mbuf *data,struct iface *iface,int32 gateway,int prec,
  265.     int del,int tput,int rel));
  266. int ppp_output __ARGS((struct iface *iface, char dest[], char source[],
  267.     int16 type, struct mbuf *data));
  268. int ppp_raw __ARGS((struct iface *iface,struct mbuf *data));
  269. void ppp_recv __ARGS((int dev,void *p1,void *p2));
  270. void ppp_autobaud __ARGS((int dev,void *p1,void *p2));
  271. void ppp_rlsd __ARGS((int dev,void *p1,void *p2));
  272. int ppp_init __ARGS((int dev));
  273. int ppp_close __ARGS((struct slip *sp, int pl_too));
  274. void pproc __ARGS((struct iface *iface,struct mbuf *bp));
  275.  
  276. /* In ppplcp.c: */
  277. struct mbuf *htoncnf __ARGS((struct cnfhdr *cnf, struct mbuf *data));
  278. int ntohcnf __ARGS((struct cnfhdr *cnf, struct mbuf **bpp));
  279. struct mbuf *htonopt __ARGS((struct opthdr *opt));
  280. int ntohopt __ARGS((struct opthdr *opt, struct mbuf **bpp));
  281.  
  282. void lcp_init __ARGS((struct slip *sp));
  283. int lcp_reset __ARGS((struct pppctl *pppiop));
  284. int lcp_close __ARGS((struct slip *sp));
  285. int lcp_start __ARGS((struct slip *sp));
  286. void lcp_shutdown __ARGS((struct slip *sp));
  287. void lcpproc __ARGS((struct iface *iface, struct mbuf *bp));
  288.  
  289. /* In pppipcp.c: */
  290. void ipcp_init __ARGS((struct slip *sp));
  291. int ipcp_reset __ARGS((struct slip *sp));
  292. int ipcp_close __ARGS((struct slip *sp));
  293. int ipcp_start __ARGS((struct slip *sp));
  294. void ipcpproc __ARGS((struct iface *iface, struct mbuf *bp));
  295.  
  296. /* In ppppap.c: */
  297. void pap_init __ARGS((struct slip *sp));
  298. int pap_reset __ARGS((struct pppctl *pppiop));
  299. int pap_start __ARGS((struct slip *sp));
  300. int pap_getpass __ARGS((struct slip *sp,int mustask));
  301. void papproc __ARGS((struct iface *iface, struct mbuf *bp));
  302.  
  303. #endif    /* PPP_ALLOC */
  304.